package Server.ServerCore.Model.Player;



import Server.ExtComponents.socket.ObjectSession;
import Server.ServerCore.Model.dbsql.model.GameRole;
import Server.ServerCore.Model.vo.CardVO;
import Server.ServerCore.Model.vo.CardResultStatusVO;
import Server.ServerCore.Service.hardCode.SessionStatus;
import Server.ServerCore.Service.service.PlayerManagerService;
import Server.ServerCore.Service.usyns.SingelTable.CircleUnit;
import javolution.util.FastList;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicInteger;


public class PlayerInstance extends GameCharacter{


    /**日志*/
    private static final Logger LOGGER= LoggerFactory.getLogger(PlayerInstance.class);

    /**角色会话*/
    private ObjectSession playerSession;

    /**角色在线状态*/
    private SessionStatus sessionStatus=SessionStatus.OFFLINE;
    private GameRole gameRole;

    /**用户帐号*/
    private String UserAccount = "";

    private String Name = "";// 对象名字

    private double BargainingChip=0;//筹码余额

    //当前箭头所指的位置 0,1,2,3,4
    private int NowCrileUnitID;

    public boolean isOver() {
        return over;
    }
    public void setOver(boolean over) {
        this.over = over;
    }

    //牌局是否结束，如果牌局没有结束掉线，那么玩家操作可能：掉线，刷新，主动关闭
    private boolean over=false;

    public boolean isBet() {
        return bet;
    }

    public void setBet(boolean bet) {
        this.bet = bet;
    }

    //玩家是否下注
    private boolean bet=false;

    //记录某个玩家每一幅牌的结果状态属性
    private CardResultStatusVO[] deckoOfCardsVOFastList=new CardResultStatusVO[15];

    //存储纸牌容器 当玩家分牌的时候，在cardVOFastList容器添加一个对象
    private FastList<CardVO> cardVOFastList=new FastList<CardVO>(12);

    private FastList<Integer> circleUnitIDS=new FastList<Integer>();


    private FastList<CircleUnit> circleUnitFastList;//circleUnit location


    private double role_Integration;//角色网站积分（购买筹码）

    //记录玩家牌数量（几幅牌）
    public  AtomicInteger atomicInteger=new AtomicInteger(0);



    public double getRole_Integration() {
        return role_Integration;
    }

    public void setRole_Integration(double role_Integration) {
        this.role_Integration = role_Integration;
    }


    public GameRole getGameRole() {
        return gameRole;
    }

    public void setGameRole(GameRole gameRole) {
        this.gameRole = gameRole;
    }


    public double getBargainingChip() {
        return BargainingChip;
    }

    public void setBargainingChip(double bargainingChip) {
        BargainingChip = bargainingChip;
    }


    public int getNowCrileUnitID() {
        return NowCrileUnitID;
    }

    public void setNowCrileUnitID(int nowCrileUnitID) {
        NowCrileUnitID = nowCrileUnitID;
    }



    public CardResultStatusVO[] getDeckoOfCardsVOFastList() {
        return deckoOfCardsVOFastList;
    }

    public void setDeckoOfCardsVOFastList(CardResultStatusVO[] deckoOfCardsVOFastList) {
        this.deckoOfCardsVOFastList = deckoOfCardsVOFastList;
    }


    public FastList<Integer> getCircleUnitIDS() {
        return circleUnitIDS;
    }

    public void setCircleUnitIDS(FastList<Integer> circleUnitIDS) {
        this.circleUnitIDS = circleUnitIDS;
    }



   public PlayerInstance(ObjectSession playerSession){
       this.playerSession=playerSession;
   }


    /**
     *
     * 获取每一幅牌的点数
     * @return
     *
     * @return
     */
    public int getPoints(){
        int pontis=0;
        for (CardVO cardVO:cardVOFastList){
            pontis+=cardVO.getPonts();
        }
        return pontis;
    }





    /**
     * 及时数据发送通道
     * 如果要求及时的数据（譬如地图同步信息）---调用此方法，会直接wirte(buf),
     * 被直接递交给netty通信底层;
     * write(Object message, SocketAddress remoteAddress)  处理 DatagramChannel
     *
     * @param bufferData
     */
    @Override
    public void DirectSend(ChannelBuffer bufferData) {
        Channel channel=this.getPlayerSession().getChannel();
        if (channel!=null)
        channel.write(bufferData);
    }

    /**
     * 持久化玩家的数据
     */
    public void save(){
        if (this.sessionStatus.equals(SessionStatus.ONLINE)){ //已经在线,保存数据
            this.LeaveSimgleTable();
            PlayerManagerService.update(this.gameRole,this.getBargainingChip());
            this.sessionStatus=SessionStatus.OFFLINE;//player state in server
        }
    }


    public FastList<CircleUnit> getCircleUnitFastList() {
        return circleUnitFastList;
    }

    public void setCircleUnitFastList(FastList<CircleUnit> circleUnitFastList) {
        this.circleUnitFastList = circleUnitFastList;
    }

    public FastList<CardVO> getCardVOFastList() {
        return cardVOFastList;
    }

    public void setCardVOFastList(FastList<CardVO> cardVOFastList) {
        this.cardVOFastList = cardVOFastList;
    }



    public SessionStatus getSessionStatus() {
        return sessionStatus;
    }


    public void setSessionStatus(SessionStatus sessionStatus) {
        this.sessionStatus = sessionStatus;
    }



    public String getUserAccount() {
        return UserAccount;
    }

    public void setUserAccount(String userAccount) {
        UserAccount = userAccount;
    }

    public ObjectSession getPlayerSession() {
        return playerSession;
    }

    public void setPlayerSession(ObjectSession playerSession) {
        this.playerSession = playerSession;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }



    public static void main(String[]args){


    }

}
